package com.smart.system.domain;

import com.baomidou.mybatisplus.annotation.*;
import com.smart.common.constant.GlobalConstants;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.*;
import com.smart.common.annotation.Excel;
import com.smart.common.core.domain.BaseEntity;

import java.util.Date;

/**
 * 考勤记录对象 attendance_record
 * 
 * @author smart
 * @date 2024-09-18
 */
@EqualsAndHashCode(callSuper = true)
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
@TableName("attendance_record")
public class AttendanceRecord extends BaseEntity
{
    private static final long serialVersionUID = 1L;

    /** 主键标识 */
    @Schema(description ="${comment}")
    @TableField(value = "id",exist = true)
    @TableId(type=IdType.AUTO)
    private Integer id;

    @Excel(name = "员工id")
    @Schema(description ="员工id")
    @TableField(value = "user_id",exist = true)
    private Integer userId;

    @Excel(name = "职位,回显数据")
    @Schema(description ="职位")
    @TableField(exist = false)
    private Integer position;

    /** 职位名称(回显数据) */
    @Excel(name = "职位名称,回显数据")
    @Schema(description ="职位名称")
    @TableField(exist = false)
    private String positionName;

    @Excel(name = "员工名称")
    @Schema(description ="员工名称")
    @TableField(value = "user_name",exist = true)
    private String userName;

    /** 考勤;0正常1迟到2旷工3请假4异常 */
    @Excel(name = "考勤;0正常1迟到2旷工3请假4异常5休息")
    @Schema(description ="考勤;0正常1迟到2旷工3请假4异常5休息")
    @TableField(value = "attendance",exist = true)
    private String attendance;

    /** 考勤时间 */
    @Excel(name = "上班考勤时间")
    @Schema(description ="上班考勤时间")
    @TableField(value = "attendance_up_time",exist = true)
    private Date attendanceUpTime;
    @Excel(name = "下班考勤时间")
    @Schema(description ="下班考勤时间")
    @TableField(value = "attendance_down_time",exist = true)
    private Date attendanceDownTime;

    /** 是否补卡;0否1是 */
    @Excel(name = "是否补卡;0否1是")
    @Schema(description ="是否补卡;0否1是")
    @TableField(value = "is_repair",exist = true)
    private String isRepair;

    /** 租户号 */
    @Excel(name = "租户号")
    @Schema(description ="租户号")
    @TableField(value = "dept_id",exist = true)
    private Long deptId;

    /** 乐观锁 */
    @Excel(name = "乐观锁")
    @Schema(description ="乐观锁")
    @TableField(value = "revision",exist = true)
    private String revision;

    @TableField(value = "attendance_date")
    @Schema(description ="考勤日期")
    private Date attendanceDate;

    @TableField(value = "replacement_date")
    @Schema(description ="补卡日期")
    private Date replacementDate;

    /**
     * 上班卡是否存在
     * @return
     */
    public boolean isAttendanceWork(){
        return this.getAttendanceUpTime() != null;
    }

    /**
     * 下班卡是否存在
     */
    public boolean isAttendanceDown(){
        return this.getAttendanceDownTime() != null;
    }

    /**
     * 是否休息
     */
    public boolean isRest(){
        return this.getAttendance() != null && this.getAttendance().equals(GlobalConstants.ATTENDANCE_REST);
    }
}
